package com.iuie.ns.system.dao.code.impl;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.iuie.ns.frame.persistence.dao.impl.GenericDaoImpl;
import com.iuie.ns.system.dao.code.ISysCodeInfoDao;
import com.iuie.ns.system.vo.code.SysCodeInfoVO;

@Repository("codeInfoDao")
public class SysCodeInfoDaoImpl extends GenericDaoImpl<SysCodeInfoVO> implements ISysCodeInfoDao{

    @Override
    public void deleteById(String id) {
        String hql = "update SysCodeInfoVO code set code.state=-1 where code.codeInfoValue=:codeInfoValue";
        Query query = getCurrentSession().createQuery(hql);
        query.setParameter("codeInfoValue", id);
        query.executeUpdate();
    }

    @Override
    public String findMaxCodeValue(String type) {
        String hql = "select max(c.codeInfoValue) from SysCodeInfoVO c where c.codeType.codeTypeId=:codeTypeId";
        Query query = this.createQuery(hql);
        query.setString("codeTypeId", type);
        Object rs = query.uniqueResult();
        if (rs != null && rs instanceof String) {
            String value = (String) rs;
            return value;
        }
        return null;
    }

}
